<template>
  <div>
    <div v-show="editStatus == false">
      
      <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
        <!--<el-table-column type="selection" width="55"></el-table-column>      -->
        <el-table-column prop="name" label="序号" width="60">
          <template slot-scope="scope">{{scope.$index+1}}</template>
        </el-table-column>
        <el-table-column prop="created_at" label="发布时间" width="100">
          <template slot-scope="scope">
            {{timeFun(scope.row.video.created_at)}}
          </template>
        </el-table-column>
        <el-table-column prop="source_thum" label="封面" width="90">
          <template slot-scope="scope">
            <img :src="scope.row.video.source_thum" style="width:70px;height:80px"/>
          </template>
        </el-table-column>
        <el-table-column prop="video.title" label="标题"> </el-table-column>      
        <el-table-column prop="type" label="分类" >
          <template slot-scope="scope">
            {{options[scope.row.type].label}} 
          </template>
        </el-table-column>  
        <el-table-column prop="marks" label="标签名" >
          <template slot-scope="scope">
            <span v-for="item in scope.row.marks"  :key="item.id" style="padding-right:10px">{{item.name}},</span>
          </template>
        </el-table-column>     
        <el-table-column prop="userInfo.userNick" label="发布者ID" width="100"> </el-table-column>      
        <el-table-column prop="video.comment_count" label="评论" width="50" > </el-table-column>      
        <el-table-column prop="video.favorites" label="喜欢" width="60"> </el-table-column>      
        <el-table-column prop="video.page_view" label="点击量" width="70">> </el-table-column>      
        <el-table-column prop="video.status" label="状态" width="50">
         
          <template slot-scope="scope">
             <span style="color:#67c23a" v-if="scope.row.video.status==1">上线</span>
            <span v-if="scope.row.video.status==2">下线</span>
            <span style="color:#fd0767" v-if="scope.row.isRecommend == 1">推荐</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scope">
            <div>
              <el-button class="addBtn" type="warning" @click="unstickFun(scope.row.video.id)" v-if="scope.row.video.order_at && userRole.VD_1401003"> 取消置顶</el-button>
              <el-button class="addBtn" type="primary" @click="stickFun(scope.row.video.id)" v-else> 置顶</el-button>
              <el-button class="addBtn" type="success" @click="edit(scope.row)" v-if="userRole.VD_1401002"> 编辑</el-button>
              <el-button v-if="scope.row.video.status==1 && userRole.VD_1401004" type="warning" class="addBtn" @click="editUpvideo(2,scope.row)">下线</el-button>
              <el-button v-if="scope.row.video.status==2 && userRole.VD_1401004" type="warning" class="addBtn" @click="editUpvideo(1,scope.row)">上线</el-button>
              <el-button class="addBtn" type="danger" @click="editUpvideo(3,scope.row)"> 删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div> 
    <div v-if="editStatus">
      <edit-viedo @showlist = "getUserlist" ref="viedo" :dataViedo="dataViedo"></edit-viedo>
    </div>
  </div>
</template>

<script>
  import editViedo from './Articel/editViedo'
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        currentPage4: 1,//分野
        total:0,
        editStatus:false,
        dialogVisible:false,
        sheachValue:'',
        seachtype:0,
        tuijians:'',
        value:'全部',
        dataViedo:'',
        options:[{
          value:0,
          label:'全部'
        },{
          value:1,
          label:'牙齿矫正'
        },{
          value:2,
          label:'种植牙'
        },{
          value:3,
          label:'口腔健康'
        },{
          value:4,
          label:'儿童口腔'
        }],
        tableData: [],
        page:1,
        pageSize:10
      }
    },
    components:{
      editViedo
    },
    props:['navStatus'],
    created() {
      this.getUserlist()
    },
    methods: {
      getUserlist() {
        const parm ={
          "pageIndex":this.page,
          "pageSize":this.pageSize,
          "title":this.sheachValue,
          "type":this.seachtype
        };
         if(this.navStatus == 0){
          parm.status = 1;
        } else if(this.navStatus == 1) {
           parm.status = 2;
        } else {
          parm.status ='';
        }
        Http.getVideoList(parm)
        .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total
          this.dataViedo='';
          this.editStatus = false
        })
        .catch( error => {
          
        })
      },   
      
      timeFun(val) {
        return getTime(val)
      },
      
      edit(val) {
        this.$emit('goEdit',val)
      },
      deletData(val) {
        this.$message.error('开发中')
      },
      sheachData(val){
        this.type = val.type;
        this.title = val.title;
        this.getUserlist()
      },
      //选择 推荐
      handleSelectionChange(val) {},

      //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getUserlist()
        
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getUserlist()
        
      },
      //视频上下线
      editUpvideo(state,row) {
        let txt = '';
        if(state === 1) {
          txt = '上线'
        } else if(state === 2){
          txt = '下线'
        } else {
          txt = '删除'
        }

        this.$confirm(`确认${txt}此视频吗 ？`)
        .then(_ => {
          Http.upVideo(state,row.video.id)
          .then( res => {
            if( res.data.code ==200){
              this.$message.success(`${txt}成功`);
              this.getUserlist()
            } else if(res.data.code == -1003) {
              this.$message.error(`请求失败原因：${res.data.message}`)
              setTimeout(()=>{
                this.$router.push('/')
              },2000)
            }
            
          })
          .catch( error => {
            this.$message.error('服务器请求失败')
          })
        })
      },
      //视频置顶
      stickFun(row) {
        
        Http.postStickVideo(row)
        .then( res => {
          if( res.data.code ==200){
            this.$message.success('置顶成功')
            this.getUserlist()
          } else if(res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
             setTimeout(()=>{
              this.$router.push('/')
            },2000)
          }
        })
        .catch( error => {
          this.$message.error('服务器请求失败')
        })
      },
      unstickFun(row) {
        
        Http.unPostStickVideo(row)
        .then( res => {
          if( res.data.code ==200){
            this.$message.success('取消置顶成功')
            this.getUserlist()
          } else if(res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
             setTimeout(()=>{
              this.$router.push('/')
            },2000)
          }
        })
        .catch( error => {
          this.$message.error('服务器请求失败')
        })
      },
      //搜索
      seachFun() {
        
        this.getUserlist()
      }
    }
  }
</script>
<style>

</style>
